using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Universe.WinForms;

namespace TmxLib
{
    public class ToolStripSearchTextBox : ToolStripControlHost
    {
        public event EventHandler Search;

        public SearchTextBox SearchTextBoxControl
        {
            get { return this.Control as SearchTextBox; }
        }

        public ToolStripSearchTextBox() : base(new SearchTextBox())
        {
        }


        public override Size GetPreferredSize(Size constrainingSize)
        {
            return this.SearchTextBoxControl.Size;
            // return base.GetPreferredSize(constrainingSize);
        }

        protected override void OnSubscribeControlEvents(Control control)
        {
            base.OnSubscribeControlEvents(control);

            SearchTextBox tb = (SearchTextBox) control;
            tb.Search += new EventHandler(tb_Search);


        }

        void tb_Search(object sender, EventArgs e)
        {
            if (Search != null)
                Search(SearchTextBoxControl, EventArgs.Empty);
        }

        protected override void OnUnsubscribeControlEvents(Control control)
        {
            base.OnUnsubscribeControlEvents(control);

            SearchTextBox tb = (SearchTextBox)control;
            tb.Search -= new EventHandler(tb_Search);
        }
    }
}
